/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package questionbook.model;

import java.util.Date;
import org.openrdf.model.Literal;
import org.openrdf.model.URI;

/**
 * Represents a asked Question in the System
 *
 * @author stefanstift
 */
public class Question extends StandardModel{

    /**
     * The title of the question
     */
    private String title;

    /**
     * The content of the question
     */
    private String text;

    /**
     * The Category that is assigned for this question
     */
    private Category category;

    /**
     * The User who asked this question
     */
    private Person  asker;

    /**
     * The create date of the Question
     */
    private Date createdAt;

    /**
     * Creates a new Question instance with the specified URI
     *
     * @param uri
     */
    public Question(URI uri) {
        super(uri);
    }

    /**
     * Creates a new Question instance with the specified URI-String
     *
     * @param uri
     */
    public Question(String uri) {
        super(uri);
    }

    /**
     *
     * @return the content of the Question as a Literal
     */
    public Literal getTextLiteral() {
        return this.getStringLiteral(text);
    }

    /**
     *
     * @return the first 20 characters of the question
     */
    public String getTextShort() {

        if(text.length() > 20)
        {
            String s = text.substring(0, 20);
            s = s + "...";
            return s;
        }

        return text;
    }

    /**
     *
     * @return the content of the Question
     */
    public String getText() {
        return text;
    }

    /**
     * Sets the content of the Question
     *
     * @param text
     */
    public void setText(String text) {
        this.text = text;
    }

    /**
     *
     * @return the User who asked the Question
     */
    public Person getAsker() {
        return asker;
    }

    /**
     * Sets the User who asked the Question
     *
     * @param asker
     */
    public void setAsker(Person asker) {
        this.asker = asker;
    }

    /**
     *
     * @return the Category of the Question
     */
    public Category getCategory() {
        return category;
    }

    /**
     * Sets the Category of the Question
     *
     * @param category
     */
    public void setCategory(Category category) {
        this.category = category;
    }

    /**
     *
     * @return the title of the Question as a Literal
     */
    public Literal getTitleLiteral() {
        return this.getStringLiteral(title);
    }

    /**
     *
     * @return the title of the Question
     */
    public String getTitle() {
        return title;
    }

    /**
     * Sets the title of the Question
     *
     * @param title
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     *
     * @return  Timestamp of Create-Date as Long-Literal
     */
    public Literal getCreatedAtLiteral() {
        return this.getLongLiteral(this.createdAt.getTime());
    }

    /**
     *
     * @return Date-Object of the Create-Date
     */
    public Date getCreatedAt() {
        return createdAt;
    }

    /**
     *
     * @return String-Representation of the Create-Date
     */
    public String getCreatedAtString() {
        return this.format.format(createdAt);
    }

    /**
     * Sets the Create-Date with a Timestamp-String
     *
     * @param timestamp
     */
    public void setCreatedAt(String timestamp) {
        this.createdAt = new Date(Long.parseLong(timestamp));
    }

    /**
     * Sets the Create-Date with a Date-Object
     *
     * @param createdAt
     */
    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

}
